﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Xml.Linq;

namespace RssFeederASPClient.Models
{
    public class RssReader
    {
        public static IEnumerable<RssProperties> GetFeed(String url)
        {
            WebClient client = new WebClient();
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            String xmlData = client.DownloadString(url);  //remember to update this url

            XDocument xml = XDocument.Parse(xmlData);

            IEnumerable<RssProperties> FBUpdates = (from story in xml.Descendants("item")
                                                    select new RssProperties
                                                    {
                                                        Title = ((string)story.Element("title")),
                                                        Link = ((string)story.Element("link")),
                                                        Description = ((string)story.Element("description")),
                                                        PubDate = ((string)story.Element("pubDate"))
                                                        //enclosureUrl = ((string)story.Attribute(""))
                                                    }).Take(10);

            return FBUpdates;
        }

    }
}